package com.nw.serviceImpl;

import com.nw.dao.LikeDao;
import com.nw.entity.Like;
import com.nw.service.LikeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class LikeServiceIpml implements LikeService {
    @Resource
    LikeDao likeDao;
    @Override
    public HashMap<String, Object> insertLike(Like like) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            like.setLikeId(UUID.randomUUID().toString());
            like.setLikeStatus("1");
            //System.out.println(like);
            likeDao.insertLike(like);
            map.put("code","0");
            map.put("msg","添加收藏成功");
        } catch (Exception e) {
            //e.printStackTrace();
            map.put("code","1");
            map.put("msg","添加收藏失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> getLike(String likeUserId) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            List<Like> like = likeDao.getLike(likeUserId);
            map.put("code","0");
            map.put("msg","查询收藏成功");
            map.put("data",like);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code","1");
            map.put("msg","查询收藏失败");
        }
        return map;

    }

    @Override
    public HashMap<String, Object> updateLikeStatus(Like like) {
        HashMap<String,Object> map = new HashMap<>();
        try {
            System.out.println("即将入库的数据为:"+like);
            likeDao.updateLikeStatus(like);
            map.put("code","0");
            map.put("msg","移除收藏成功");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code","1");
            map.put("msg","移除收藏失败");
        }
        return map;
    }
}
